import 'package:flutter/painting.dart';
import 'package:pp_uikit/bottom_sheet/pp_action_sheet_theme.dart';
import 'package:pp_uikit/tabbar/pp_tabbar_theme.dart';
import 'package:pp_uikit/theme/pp_selection_theme.dart';

class PPThemeConfig {
  String? supportLanguageCode;

  String? imagePlaceholder;
  Color? brandPrimary;
  Color? backgroundColor;

  /// 渐变色 左
  Color? gradientLeft;

  /// 渐变色 右，与 [brandPrimary] 同一个颜色
  // Color? gradientRight;

  PPThemeConfig({
    this.supportLanguageCode,
    this.brandPrimary,
    this.backgroundColor,
    this.gradientLeft,
    this.imagePlaceholder,
  }) : super();
}

class PPDefaultTheme {
  PPDefaultTheme._() {
    // _checkAndInitConfig();
  }

  static final PPDefaultTheme _instance = PPDefaultTheme._();

  static PPDefaultTheme get instance {
    return _instance;
  }

  void setup(PPThemeConfig config) {
    supportLanguageCode = config.supportLanguageCode;
    _brandPrimary = config.brandPrimary;
    _backgroundColor = config.backgroundColor;
    _gradientLeft = config.gradientLeft;
    imagePlaceholder = config.imagePlaceholder;
  }

  String? supportLanguageCode;

  String? imagePlaceholder;

  /// 文本字号
  /// 特殊数据展示，Bebas 数字字体，用于强吸引
  static const fontSizeBebas = 28.0;

  /// 标题字体
  /// 名称/页面大标题
  static const fontSizeHeadLg = 22.0;

  /// 标题字体
  /// 内容模块标题/一级标题
  static const fontSizeHead = 18.0;

  /// 子标题字体
  /// 标题/录入文字/大按钮文字/二级标题
  static const fontSizeSubHead = 16.0;

  /// 基础字体
  /// 内容副文本/普通说明文字
  static const fontSizeBase = 14.0;

  /// 辅助字体-普通
  static const fontSizeCaption = 12.0;

  ///辅助字体-小
  static const fontSizeCaptionSm = 11.0;

  /// 圆角尺寸
  static const radiusXs = 2.0;
  static const radiusSm = 4.0;
  static const radiusMd = 8.0;
  static const radiusLg = 12.0;

  /// 边框尺寸
  static const borderWidthSm = 0.5;
  static const borderWidthMd = 1.0;
  static const borderWidthLg = 2.0;

  /// 水平间距
  static const hSpacingXs = 8.0;
  static const hSpacingSm = 12.0;
  static const hSpacingMd = 16.0;
  static const hSpacingLg = 20.0;
  static const hSpacingXl = 24.0;
  static const hSpacingXxl = 42.0;

  /// 垂直间距
  static const vSpacingXs = 4.0;
  static const vSpacingSm = 8.0;
  static const vSpacingMd = 12.0;
  static const vSpacingLg = 14.0;
  static const vSpacingXl = 16.0;
  static const vSpacingXxl = 28.0;

  /// 图标大小
  static const iconSizeXxs = 8.0;
  static const iconSizeXs = 12.0;
  static const iconSizeSm = 14.0;
  static const iconSizeMd = 16.0;
  static const iconSizeLg = 32.0;

  /// 主题色相关
  /// 主题色
  Color? _brandPrimary;
  Color get brandPrimary => _brandPrimary ?? const Color(0xFFFF682F);

  /// -----------  渐变  -----------
  /// 渐变色 左
  Color? _gradientLeft;
  Color get gradientLeft => _gradientLeft ?? const Color(0xFFFF8124);

  /// 渐变色 左 (50%)
  Color get gradientLeft50 => gradientLeft.withOpacity(0.5);

  /// 渐变色 右
  Color get gradientRight => brandPrimary;

  /// 渐变色 右 (50%)
  Color get gradientRight50 => brandPrimary.withOpacity(0.5);

  /// 主题色按下效果
  static const brandPrimaryTap = Color(0x19FF682F);

  /// 成功色
  static const brandSuccess = Color(0xFF00AE66);

  /// 警告色
  static const brandWarning = Color(0xFFFAAD14);

  /// 失败色
  static const brandError = Color(0xFFFF2727);

  /// 重要-多用于红点色
  static const brandImportant = Color(0xFFFA3F3F);

  /// 重要数值色
  static const brandImportantValue = Color(0xFFFF5722);

  /// 辅助色
  static const brandAuxiliary = Color(0xFF44C2FF);

  /// 线条色
  static const Color lineColor = Color(0xFFEEEEEE);

  /// 文本色相关
  /// 基础文字纯黑色
  Color? _colorTextBase;
  Color get colorTextBase => _colorTextBase ?? const Color(0xFF333333);

  /// 基础文字重要色
  Color? _colorTextImportant;
  Color get colorTextImportant =>
      _colorTextImportant ?? const Color(0xFF666666);

  /// 基础文字-反色
  static const colorTextBaseInverse = Color(0xFFFFFFFF);

  /// 辅助文字色
  Color? _colorTextSecondary;
  Color get colorTextSecondary =>
      _colorTextSecondary ?? const Color(0xFF999999);

  /// 失效或不可更改文字色
  static const colorTextDisabled = Color(0xFF999999);

  /// 文本框提示暗文文字色
  static const colorTextHint = Color(0xFFCCCCCC);

  /// 跟随主题色[brandPrimary]
  static const colorLink = Color(0xFF4680FF);

  /// 背景色相关
  ///
  /// 组件背景色
  static const fillBase = Color(0xFFFFFFFF);

  /// 页面背景色
  static const fillBody = Color(0xFFF8F8F8);

  /// 遮罩背景
  static const fillMask = Color(0x99000000);

  /// 边框色
  static const borderColor = Color(0xFFAAAAAA);
  static const borderColorBase = Color(0xFFF0F0F0);

  /// 分割线色
  static const dividerColorBase = Color(0xFFF0F0F0);

  /// 背景色
  Color? _backgroundColor;
  Color get backgroundColor => _backgroundColor ?? const Color(0xFFF7F7F7);

  static PPActionSheetTheme defaultActionSheetConfig = PPActionSheetTheme(
    topRadius: PPDefaultTheme.radiusLg,
    titleStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeSubHead,
    ),
    itemTitleStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: fontSizeSubHead,
      fontWeight: FontWeight.w300,
    ),
    itemTitleStyleLink: const TextStyle(
      fontSize: fontSizeSubHead,
      fontWeight: FontWeight.w300,
      color: colorLink,
    ),
    itemTitleStyleAlert: const TextStyle(
      color: brandError,
      fontSize: fontSizeSubHead,
      fontWeight: FontWeight.w300,
    ),
    itemDescStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: fontSizeCaption,
      fontWeight: FontWeight.w300,
    ),
    itemDescStyleLink: const TextStyle(
      color: colorLink,
      fontSize: fontSizeCaption,
      fontWeight: FontWeight.w300,
    ),
    itemDescStyleAlert: const TextStyle(
      color: brandError,
      fontSize: fontSizeCaption,
      fontWeight: FontWeight.w300,
    ),
    cancelStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: fontSizeSubHead,
      fontWeight: FontWeight.w300,
    ),
    titlePadding: const EdgeInsets.only(left: 12),
    contentPadding:
        const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
  );

  /// 筛选项配置
  static PPSelectionTheme defaultSelectionConfig = PPSelectionTheme(
    menuNormalTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    menuSelectedTextStyle: TextStyle(
      fontWeight: FontWeight.w600,
      fontSize: PPDefaultTheme.fontSizeBase,
      color: PPDefaultTheme.instance.brandPrimary,
    ),
    tagNormalTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeCaption,
    ),
    tagSelectedTextStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeCaption,
      fontWeight: FontWeight.w600,
    ),
    tagRadius: PPDefaultTheme.radiusSm,
    tagNormalBackgroundColor: PPDefaultTheme.fillBody,
    tagSelectedBackgroundColor:
        PPDefaultTheme.instance.brandPrimary.withOpacity(0.12),
    rangeTitleTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeSubHead,
      fontWeight: FontWeight.w600,
    ),
    hintTextStyle: const TextStyle(
      color: PPDefaultTheme.colorTextHint,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    inputTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    itemNormalTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    itemSelectedTextStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeBase,
      fontWeight: FontWeight.w600,
    ),
    itemBoldTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeBase,
      fontWeight: FontWeight.w600,
    ),
    lightSelectBgColor: const Color(0xFFFFFFFF),
    lightNormalBgColor: const Color(0xFFFFFFFF),
    middleSelectBgColor: const Color(0xFFFFFFFF),
    middleNormalBgColor: const Color(0xFFF8F8F8),
    deepSelectBgColor: const Color(0xFFF8F8F8),
    deepNormalBgColor: const Color(0xFFF0F0F0),
    resetTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextImportant,
      fontSize: PPDefaultTheme.fontSizeCaption,
    ),
    titleForMoreTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeBase,
      fontWeight: FontWeight.w600,
    ),
    optionTextStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    moreTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextSecondary,
      fontSize: PPDefaultTheme.fontSizeCaption,
    ),
    flayerNormalTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeSubHead,
    ),
    flayerSelectedTextStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeSubHead,
      fontWeight: FontWeight.w600,
    ),
    flayerBoldTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextBase,
      fontSize: PPDefaultTheme.fontSizeSubHead,
      fontWeight: FontWeight.w600,
    ),
  );

  /// TabBar配置
  static PPTabBarTheme defaultTabBarConfig = PPTabBarTheme(
    backgroundColor: const Color(0xFFFFFFFF),
    tabHeight: 40.0,
    indicatorHeight: 3.0,
    indicatorWidth: 24.0,
    labelStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeSubHead,
      fontWeight: FontWeight.w600,
    ),
    unselectedLabelStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextImportant,
      fontSize: PPDefaultTheme.fontSizeBase,
      fontWeight: FontWeight.normal,
    ),
    tagRadius: PPDefaultTheme.radiusSm,
    tagNormalTextStyle: TextStyle(
      color: PPDefaultTheme.instance.colorTextImportant,
      fontSize: PPDefaultTheme.fontSizeBase,
    ),
    tagNormalBgColor: PPDefaultTheme.fillBody,
    tagSelectedTextStyle: TextStyle(
      color: PPDefaultTheme.instance.brandPrimary,
      fontSize: PPDefaultTheme.fontSizeSubHead,
    ),
    tagSelectedBgColor: PPDefaultTheme.instance.brandPrimary.withAlpha(0x14),
    tagSpacing: 12.0,
    preLineTagCount: 4,
    tagHeight: 32.0,
  );
}
